<template>
  <XcDrawer ref="drawer" :title="$t('page.app.depends')" :width="640" @onDrawerSave="onSave">
    <CheckboxGroup v-model="depends.list">
      <Checkbox v-for="(d, i) in depends.all" :key="i" :label="d.name"></Checkbox>
    </CheckboxGroup>
  </XcDrawer>
</template>

<script>
  import XcDrawer from '@/components/xcdrawer'
  export default {
    name: "comp-configdepend",
    components: { XcDrawer },
    data() {
      return {
        name: '',
        depends: {
          list: [],
          all: []
        },
      }
    },
    methods: {
      show(name) {
        if (!name) return
        this.name = name
        this.depends.list = []
        // 加载
        this.$md.dispatch('app_config_depends', {
          data: name
        }).then(data => {
          if (data.retCode === 1) {
            let all = data.data || []
            if (all.length === 0) {
              this.$Message.warning(this.$t('page.app.dependsnone'))
              this.$refs.drawer.close(true)
              return
            }
            this.depends.all = all
            this.depends.list = data.depends || []
            this.$refs.drawer.show()
          }
        })
      },
      onSave() {
        this.$md.dispatch('app_depend_edit', {
          data: {
            name: this.name,
            depends: this.depends.list.join(',')
          }
        }).then(data => {
          if (data.retCode === 1) {
            this.$Message.success(this.$t('submitok'))
            this.$refs.drawer.close(true)
          }
        })
      }
    }
  };
</script>
